<template src="./template.html"></template>

<script>
import LayoutToLesson from '../layout'
import { SALES_LANGUAGE } from './consts'
import FollowPage from './follow/index.vue'
// import { getExercise } from '../models'

export default {
  components: { LayoutToLesson, FollowPage },
  data() {
    return {
      SALES_LANGUAGE,
      activeTab: 'lesson',
      exerciseList: [],
    }
  },
  computed: {
    infos() {
      return this.$store.state.pageStatusInfo.courseLayoutInfoData || { courseIntroduction: '', lessons: [] }
    }
  },
  methods: {
    getFileSize(bytes) {
      // 将byte大小转换成MB或者GB
      if (!bytes || bytes === 0) return '0 B'
      const k = 1024
      const sizes = ['B', 'KB', 'MB', 'GB']
      const i = Math.floor(Math.log(bytes) / Math.log(k))
      // 保留两位小数
      const size = (bytes / (k ** i)).toFixed(2)
      return `${size}${sizes[i]}`
    },
    getFlieIcon(item) {
      if (['mp4'].includes(item.fileExtension)) {
        return 'assets/images/att-icon-video.png'
      } else if (['mp3'].includes(item.fileExtension)) {
        return 'assets/images/att-icon-audio.png'
      } else if (['ppt'].includes(item.fileExtension)) {
        return 'assets/images/att-icon-ppt.png'
      } else {
        return 'assets/images/att-icon.png'
      }
    },
    $initSalesLanguage(salesLanguageMap) {
      return this.SALES_LANGUAGE.map(it => ({
        ...it,
        content: salesLanguageMap[it.params]
      }))
    },
    $parseKeywords(keywords) {
      if (!keywords || typeof keywords !== 'string') {
        return []
      }
      // 定义可能的分隔符
      const delimiters = ['，', ',', '， ', ', ', '、']
      // 找出第一个存在的分隔符
      let delimiter = ''
      for (let i = 0; i < delimiters.length; i++) {
        if (keywords.indexOf(delimiters[i]) !== -1) {
          delimiter = delimiters[i]
          break
        }
      }
      // 如果找到分隔符，进行切割
      if (delimiter) {
        return keywords.split(delimiter).map((item) => item.trim()).filter((item) => item)
      }
      // 如果没有找到分隔符，返回单个元素的数组
      return keywords.trim() ? [keywords.trim()] : []
    },
  },
  mounted() {
    // this.$getExercise()
    console.log(this.$scopedSlots.default)
  }
}
</script>
